import React, { Component } from 'react'
import { Form, Input } from 'antd'
import PropTypes from 'prop-types'

/**
 * 添加分类的form组件
 */
const Item = Form.Item;
export default class UpdateForm extends Component {
    static propTypes = {
        // categoryName: PropTypes.string.isRequired,
        setForm: PropTypes.func.isRequired
    }

    onFinish = (values) => {
        console.log('Received values from form: ', values);
    };

    componentWillMount() {
        // 将form对象通过setForm()传递父组件
        //console.log("setForm",this.props.setForm);
        //console.log(this.refs.form);
        //this.props.setForm(this.props.form)
    }

    componentDidUpdate() {
        this.props.setForm(this.refs.form)
        // console.log(this.refs.form);
        this.refs.form.setFieldsValue({
            catName: this.categoryName
        })
    }

    render() {

        const { categoryName } = this.props
        this.categoryName = categoryName;
        // console.log(this.categoryName);
        return (
            <Form onFinish={this.onFinish} ref="form">
 
                <Item name="catName" rules={[{ required: true, message: '分类名称必须输入' }]}>
                    <Input placeholder="请输入分类名称"></Input>
                </Item>
            </Form>
        )
    }
}